package com.example.controller;

import com.example.entity.Student;
import com.example.service.studentservice;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

@Controller
@RequestMapping("/addstudent")
public class studentController {
    @Resource(name = "studentService")
    private studentservice studentService;

    /**
     * 学生表控制层
     * @param student 实体
     * @return 新增结果
     */
    @RequestMapping("/add")
    public String add(Student student, Model model, HttpServletRequest request) {
        String sid = UUID.randomUUID().toString();
        student.setSid(sid);

        int flag = studentService.insert(student);
        request.setAttribute("student",student);
        if (flag > 0) {
            model.addAttribute("flag", "插入成功!");
            return "studentinfo";
        }
        model.addAttribute("flag", "插入失败!");

        return "fail";
    }

    @RequestMapping("/test")
    public void test() {
        System.out.println("test...");
    }


}
